package com.ita.servlet.menu;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ita.factory.MServiceFactory;
import com.ita.service.MenuService;
import com.ita.util.Constant;
import com.ita.util.JsonUtil;
import com.ita.vo.JsonResult;


@WebServlet("/sec/menu/del")
public class DeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private MenuService fService;   
    
    public DeleteServlet() {
        super();
        fService = MServiceFactory.getMenuService();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		String id=request.getParameter("id");
		String mid = request.getParameter("mid");

		int m = fService.deleteMenu(id, mid);
	
		JsonResult jsonResult = new JsonResult();
		String info ="";
		if (m > 0) {
			jsonResult.setCode(Constant.SUCEESS_CODE);
			info = "Del Success!";
		} else {	
			jsonResult.setCode(Constant.FAIL_CODE);
			info = "Del Fail!";
		}
		

		jsonResult.setMsg(info);
		String json = JsonUtil.getJsonFromObject(jsonResult);

		PrintWriter out = response.getWriter();
		out.write(json);
		out.flush();
		out.close();
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
